package com.atguigu;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Tuple;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class RedisClient {
    public static void main(String[] args) {

        //通过连接池获取链接
//        JedisPool jedisPool = new JedisPool("hadoop102",6379);
//        Jedis jedis = jedisPool.getResource();

        Jedis jedis = RedisPool.getJedis();

        //获取Redis链接
//        Jedis jedis = new Jedis("hadoop102",6379);

//        System.out.println(jedis.ping());
        //写数据
        //String
        jedis.set("1109String", "good");
        //List
        jedis.lpush("1109List", "good");
        //Set
        jedis.sadd("1109Set", "good");
        //Hash
        jedis.hset("1109Hash", "1109", "good");
        //Zset
        jedis.zadd("1109Zset", 100.00, "good");

        //通常情况下，写数据不需要返回，读数据必须要返回

        //读数据
        //String
        String string = jedis.get("1109String");
        System.out.println(string);

        //List
        List<String> lrange = jedis.lrange("1109List", 0, -1);
        System.out.println(lrange);

        //Set
        Set<String> smembers = jedis.smembers("1109Set");
        System.out.println(smembers);

        //Hash
        Map<String, String> stringStringMap = jedis.hgetAll("1109Hash");
        System.out.println(stringStringMap);

        //Zset
        Set<Tuple> tuples = jedis.zrangeByScoreWithScores("1109Zset", 0, 100);
        System.out.println(tuples);


        //关闭redis链接
        /*jedis.close();
        jedisPool.close();*/
        RedisPool.closeResource();
    }
}
